package com.sanrenzu.chunbo.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.sanrenzu.chunbo.R;
import com.sanrenzu.chunbo.bean.zxb.QiangGouChildBean;
import com.sanrenzu.chunbo.dao.Collection;
import com.sanrenzu.chunbo.ui.vertical.fenlei.FenLeiActivity;
import com.sanrenzu.chunbo.widget.AmountView;

import java.util.List;

import butterknife.BindView;

/**
 * Created by My on 2016/9/3.
 */
public class ShopListview extends BaseAdapter {

    private List<Collection> list = null;
    private Context context;
    private LayoutInflater inflater;

    public ShopListview(Context context, List<Collection> list) {
        this.context = context;
        this.list = list;
        inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView( int position, View convertView, ViewGroup parent) {
        mViewHolder mHolder = null;
        if(convertView==null){
            convertView = inflater.inflate(R.layout.shop_car_item,parent,false);
            mHolder = new mViewHolder(convertView);
            convertView.setTag(mHolder);
        }else {
            mHolder = (mViewHolder) convertView.getTag();
        }

        mHolder.shopName.setText(list.get(position).getProductName());
        mHolder.shopMoney.setText(list.get(position).getProductMarketPrice());
        Glide.with(context).load(list.get(position).getProduct_images()+"").into(mHolder.shopImage);


        mHolder.shopView.setGoods_storage(50);
        mHolder.shopView.setOnAmountChangeListener(new AmountView.OnAmountChangeListener() {
            @Override
            public void onAmountChange(View view, int amount) {
                Toast.makeText(context, "您选购的数量：" + amount, Toast.LENGTH_SHORT).show();
            }
        });


        return convertView;
    }

    class mViewHolder {
       private ImageView shopImage;
       private TextView shopName;
       private TextView shopMoney;
       private AmountView shopView;
        public mViewHolder(View convertView) {
            shopImage = (ImageView) convertView.findViewById(R.id.shop_image);
            shopName = (TextView) convertView.findViewById(R.id.shop_name);
            shopMoney = (TextView) convertView.findViewById(R.id.shop_money);
            shopView = (AmountView) convertView.findViewById(R.id.shop_view);
        }
    }
}
